package com.ejlchina.tool.enums

import java.io.File

enum class AntiPinchModeEnum(val index: Int, val info: String){
    NO_ANTI_PINCH(0, "不防夹"),
    CLOSE_ANTO_PINCH(1,"关门防夹"),
    OPEN_ANTI_PINCH(2,"开门防夹");
    companion object{
        fun getFromIndex(index: Int): AntiPinchModeEnum{
            return when(index){
                0 -> NO_ANTI_PINCH
                1 -> CLOSE_ANTO_PINCH
                else -> OPEN_ANTI_PINCH
            }
        }
    }
}


enum class RotateDirectionEnum(val direction: Int,val index: Int){
    CW(0, 0),
    CCW(1, 1)
}

enum class SuccessFailEnum(val value: Int){
    SUCCESS(1),FAIL(2)
}

enum class OnOffEnum(val value: Int) {
    OFF(0) {
        override fun isOn(): Boolean {
            return false
        }
    },
    ON(1) {
        override fun isOn(): Boolean {
            return true
        }
    };

    abstract fun isOn(): Boolean

    companion object{
        fun getFromIndex(index: Int): OnOffEnum{
            return when(index){
                0 -> OFF
                else -> ON
            }
        }
    }
}

enum class UpgradeStateEnum{
    NO_UPGRADE, UPGRADE_ENABLE, UPGRADE_DISABLE
}

enum class NpnEnum(val value: Int){
    OPEN(0), CLOSE(1)
}

enum class ExtendSerialPortEnum(val value: Int){
    OPEN(1), CLOSE(0)
}

enum class FanControlEnum(val value: Int){
    OFF(0),TEMPERATURE_CONTROL(1),ON(2);

    companion object{
        fun getFromValue(value: Int): FanControlEnum{
            return when(value){
                0 -> OFF
                1 -> TEMPERATURE_CONTROL
                else -> ON
            }
        }

        fun getTextResult(fanControlEnum: FanControlEnum): String{
            return when (fanControlEnum){
                OFF -> "关闭"
                TEMPERATURE_CONTROL -> "温度控制"
                else -> "常开"
            }
        }
    }
}

enum class LightTimeGetEnum(val value: Int){
    LIGHT_ON(1),LIGHT_OFF(2),LIGHT_SET(3)
}

enum class ScanCardEnum(val value: Int){
    SCAN(0),CARD(1);

    companion object{
        fun getFromValue(value: Int): ScanCardEnum{
            return when(value){
                0 -> SCAN
                else -> CARD
            }
        }
    }
}

enum class SelectMode{
    RADIO, MULTI
}

enum class ReuseTypeEnum(val value: Int){
    REUSE_OFF(0),AUTO_BREAK(1),BOTTLE_DELIVER(2),BOTTLE_COUNT(3);

    companion object{
        fun getEnumFromValue(value: Int): ReuseTypeEnum{
            return when(value){
                0 -> REUSE_OFF
                1 -> AUTO_BREAK
                2 -> BOTTLE_DELIVER
                else -> BOTTLE_COUNT
            }
        }
    }
}

interface NextStateInterface{
    fun nextState(): DoorStateEnum
}
enum class DoorStateEnum(val value: Int,val state: String): NextStateInterface{
    OPEN(1,"门控(已开门)"){
        override fun nextState(): DoorStateEnum {
            return OPEN_DOING
        }

    }, CLOSE(3,"门控(已关门)"){
        override fun nextState(): DoorStateEnum {
            return OPEN_DOING
        }

    }, OPEN_DOING(2,"门控(开门中)"){
        override fun nextState(): DoorStateEnum {
            return OPEN
        }

    }, CLOSE_DOING(4,"门控(关门中)"){
        override fun nextState(): DoorStateEnum {
            return CLOSE
        }
    }
}

enum class FirmwareUpgradeResultEnum(val resultCode: Int,val resultString: String){
    SUCCESS(0,"成功"),
    FAIL(1,"失败"),
    TIMEOUT(2,"传输超时"),
    TYPE_ERROR(3,"文件类型错误"),
    NO_ENOUGH_SPACE(11,"控件不足"),
    FILE_CRC_ERROR(12,"文件 CRC 校验失败"),
    PACKAGE_CRC_ERROR(14,"当前文件包 CRC 校验失败"),
    UNKNOWN_ERROR(99,"未知错误");

    companion object{
        fun getResultStringFromResultCode(resultCode: Int): FirmwareUpgradeResultEnum{
            return when(resultCode){
                0 -> SUCCESS
                1 -> FAIL
                2 -> TIMEOUT
                3 -> TYPE_ERROR
                11 -> NO_ENOUGH_SPACE
                12 -> FILE_CRC_ERROR
                14 -> PACKAGE_CRC_ERROR
                else -> UNKNOWN_ERROR
            }
        }
    }
}